package com.example.juc.until;

import org.junit.Test;

import java.util.concurrent.SynchronousQueue;

public class SynchronousQueueTest {
    //同步队列  队列里面只能存储一个元素 否则添加不进去
    private SynchronousQueue synchronousQueue =new SynchronousQueue();
    @Test
    public void Test1(){
        new Thread(() -> {
            try {
                System.out.println(Thread.currentThread().getName()+"+====A");
                synchronousQueue.put("A");
                System.out.println(Thread.currentThread().getName()+"+====B");
                synchronousQueue.put("B");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"AA").start();


        new Thread(() -> {
            try {
                System.out.println(Thread.currentThread().getName()+"-====A");
                synchronousQueue.take();
                System.out.println(Thread.currentThread().getName()+"-====B");
                synchronousQueue.take();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"BB").start();
    }
}
